package com.example.yunifang;

import java.util.HashMap;

import org.apache.http.HttpResponse;

import com.example.yunifang.fragment.Fragment4;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;

public class DengluActivity extends Activity implements OnClickListener {

	private TextView denglu_zhanghao_title;
	private TextView denglu_shouji_title;
	private ImageView denglu_QQ;
	private EditText et_yanzheng;
	private Button button_yangzheng;
	private EditText et_shouji;
	private EditText et_passwrod;
	private TextView tv_wjmima;
	private TextView denglu_zhuce;
	private ImageView denglu_weixin;
	private ImageView denglu_xinlang;
	private ImageView denglu_login_back;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_denglu);
		ShareSDK.initSDK(this);
		init();
	}

	private void init() {
		// TODO Auto-generated method stub
		denglu_zhanghao_title = (TextView) findViewById(R.id.denglu_zhanghao_title);
		denglu_shouji_title = (TextView) findViewById(R.id.denglu_shouji_title);
		denglu_QQ = (ImageView) findViewById(R.id.denglu_QQ);
		et_yanzheng = (EditText) findViewById(R.id.et_login_yanzheng);
		button_yangzheng = (Button) findViewById(R.id.button_login_yanzheng);
		et_shouji = (EditText) findViewById(R.id.et_login_shouhao);
		et_passwrod = (EditText) findViewById(R.id.et_login_passwrod);
		tv_wjmima = (TextView) findViewById(R.id.tv_login_wjmima);
		denglu_zhuce=(TextView)findViewById(R.id.denglu_zhuce);
		denglu_weixin=(ImageView)findViewById(R.id.denglu_weixin);
		denglu_xinlang=(ImageView)findViewById(R.id.denglu_xinlang);
		denglu_login_back=(ImageView)findViewById(R.id.denglu_login_back);
		denglu_zhanghao_title.setTextColor(Color.RED);
		denglu_QQ.setOnClickListener(this);
		denglu_shouji_title.setOnClickListener(this);
		denglu_zhanghao_title.setOnClickListener(this);
		denglu_zhuce.setOnClickListener(this);
		denglu_weixin.setOnClickListener(this);
		denglu_xinlang.setOnClickListener(this);
		denglu_login_back.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.denglu, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.denglu_shouji_title:
			denglu_zhanghao_title.setBackgroundResource(R.drawable.bg_login);
			denglu_shouji_title.setBackgroundColor(Color.WHITE);
			denglu_shouji_title.setTextColor(Color.RED);
			denglu_zhanghao_title.setTextColor(Color.BLACK);
			Toast.makeText(this, "系统维护，请暂时使用QQ登录", 0).show();
			break;
		case R.id.denglu_zhanghao_title:
			denglu_shouji_title.setBackgroundResource(R.drawable.bg_login);
			denglu_zhanghao_title.setBackgroundColor(Color.WHITE);
			denglu_shouji_title.setTextColor(Color.BLACK);
			denglu_zhanghao_title.setTextColor(Color.RED);
			break;
		case R.id.denglu_QQ:
			Platform qq = ShareSDK.getPlatform(this, QQ.NAME);

			qq.authorize();

			qq.setPlatformActionListener(new PlatformActionListener() {

				@Override
				public void onError(Platform qq, int arg1, Throwable arg2) {
					// 弹出失败窗口
					System.out.println("第三方登录失败");
				}

				@Override
				public void onComplete(Platform qq, int arg1,
						HashMap<String, Object> arg2) {
					String userName = qq.getDb().getUserName();
					String userImg = qq.getDb().getUserIcon();

					if (userImg != null) {
						Intent intent = new Intent(DengluActivity.this,
								ZhuActivity.class);
						intent.putExtra("userImg", userImg);
						startActivity(intent);
						// ZhuActivity.zhu_vp.setCurrentItem(3);
						finish();
					}
				}

				@Override
				public void onCancel(Platform arg0, int arg1) {

				}
			});
			break;
		case R.id.denglu_zhuce:
			Toast.makeText(this, "系统维护，请暂时使用QQ登录", 0).show();
			break;
		case R.id.denglu_weixin:
			Toast.makeText(this, "系统维护，请暂时使用QQ登录", 0).show();
			break;
		case R.id.denglu_xinlang:
			Toast.makeText(this, "系统维护，请暂时使用QQ登录", 0).show();
			break;
		case R.id.denglu_login_back:
			finish();
			overridePendingTransition(R.anim.infragment, R.anim.outfragment);
			break;
		default:
			break;
		}
	}
}
